//
//  navigationController.m
//  jiejie
//
//  Created by 999999999999 on 16/8/12.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "navigationController.h"
#import "UIView+BSFrame.h"
@implementation navigationController

-(void)viewDidLoad {
    [super viewDidLoad];
}
//可以在这个方法中拦截所有push进来的控制器
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    //导航栏
    [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:(UIBarMetricsDefault)];

        //固定格式
//    viewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:(UIBarButtonItemStyleDone) target:self action:nil];
    
//****自定义(initWithCustomView)button格式
    if (self.viewControllers.count > 0) {  //只包括子控制器
        UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [button setTitle:@"返回" forState:(UIControlStateNormal)];
        [button setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:(UIControlStateNormal)];
        [button setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:(UIControlStateSelected)];
        button.size = CGSizeMake(70, 30);
        /**
         按钮展示在fram上的效果..对imageView有效果
         *  contentMode
         */
//        button.contentMode = UIViewContentModeLeft;
        
        /**
         *  对button设置用contentHorizontalAlignment
          btn内部所有内容水平左对齐,
         */
         button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        //页边距
        button.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
        
        [button setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        [button setTitleColor:[UIColor redColor] forState:(UIControlStateHighlighted)];
        //点击事件
        [button addTarget:self action:@selector(back) forControlEvents:(UIControlEventTouchUpInside)];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
        

        
        //隐藏tabbar
        viewController.hidesBottomBarWhenPushed = YES;

        
    }
    //放到后边是先设置子控制器,在显示返回,显示再创建 (如果进来的不是第一个控制器,先push)
    //这句放到后边是viewcontroller可以覆盖上面设置的leftBarButtonItem
    [super pushViewController:viewController animated:animated];
}
-(void)back{
    [self popViewControllerAnimated:YES];
}
@end
